<template>
    <list-layout class="list-container">
        <div class="app-container">
            <div class="container-header">
                <div class="header-left">
                    {{$t('statistical.defectStatistical')}}
                </div>
            </div>

            <el-tabs type="border-card" class="mt10" v-model="activeName">
                <el-tab-pane :label="$t('statistical.InspectionItemDefect')" name="0">
                    <inspection-item-compontent v-if="activeName === '0'" />
                </el-tab-pane>
                <el-tab-pane :label="$t('statistical.mterialDefect')" name="1">
                    <masterial-compontent v-if="activeName === '1'" />
                </el-tab-pane>
                <el-tab-pane :label="$t('statistical.supplierDefect')" name="2">
                    <supplier-compontent v-if="activeName === '2'" />
                </el-tab-pane>
            </el-tabs>
        </div>
    </list-layout>
</template>
<script>
import {refreshCache,} from '@/api/basic/dict/type'
import {delMaterialType, importMaterialType, listALLMaterialType, listMaterialType,} from '@/api/basic/materialtype'

import inspectionItemCompontent from './inspectionItem.vue'
import masterialCompontent from './masterial.vue'
import supplierCompontent from './supplier.vue'
import {listALLFactory} from '@/api/basic/factory'

export default {
    name: 'materialType',
    components: {
        inspectionItemCompontent,
        masterialCompontent,
        supplierCompontent,
    },
    dicts: [
        'NYIQC_GAUGE_TYPE', //量具类型
        'NYIQC_MATERIAL_MIDDLE',
        'NYIQC_MATERIAL_MAX',
        'NYIQC_MATURITY',
    ],
    // components:{Detail},
    data() {
        return {
            dialogType: 1, //1:新增  2：编辑 3：查看
            dialogForm: {},
            materialTypeOptions: [],
            direction: 'rtl',
            addInspection: false,
            visible: false,
            drawer: false,
            approvalOpen: false,
            viewModel: {
                inspectionInformation: '0',
            },
            editModel: {
                inspectionInformation: '0',
            },
            approvalForm: {
                status: '1',
                textarea: '',
            },
            selBtn: 1,
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                typeCode: '',
                typeName: '',
                typeCode: '',
                materialMiddle: [],
                materialMax: [],
            },
            // 表单参数
            form: undefined,
            exportLoading: false,
            fullscreen: false,
            factoryOptions: [],
            activeName: '0',
        }
    },
    created() {
        // this.getList();
        this.getFactoryList()
    },
    methods: {
        filterParams(p) {
            if (p && p.length) {
                let index = (p || []).findIndex((i) => i === '全部')
                console.log(index)
                index >= 0 ? p.splice(index, 1) : p
                return p.join(',')
            } else {
                return ''
            }
        },
        drawerClose() {
            this.drawer = false
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            let params = JSON.parse(JSON.stringify(this.queryParams))
            params.materialMax = this.filterParams(params.materialMax)
            params.materialMiddle = this.filterParams(params.materialMiddle)
            listMaterialType(params).then((response) => {
                if (response.code == 200 && response.rows) {
                    this.typeList = response.rows
                    this.total = response.total
                    this.loading = false
                }
            })
        },
        // 获取厂区数据
        getFactoryList() {
            listALLFactory().then((res) => {
                this.factoryOptions = res.data
            })
        },
        handleMaterialMessageTypeChange(e) {
            console.log('无聊', e)
            this.queryParams.gaugeType = e.join(',')
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.form = {}
            this.dialogType = 1
            this.visible = true
        },
        handleApproval() {
            if (this.ids.length === 0) {
                this.$modal.msgWarning('请至少选择一条检验单!')
                return
            }
            this.handleDelete()
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.typeName)
            // this.single = selection.length!=1
            // this.multiple = !selection.length
        },

        materialTypeRemoteMethod(e) {
            listALLMaterialType({ materialTypeName: e }).then((res) => {
                this.materialTypeOptions = res.data
            })
        },
        handleMaterialMaxChange(e) {
            this.queryParams.materialMax = e.join(',')
        },
        handleMaterialMiddleChange(e) {
            this.queryParams.materialMiddle = e.join(',')
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const dictIds = (row && row.typeName) || this.ids
            this.$modal
                .confirm('是否确认删除类型名称为"' + dictIds + '"的数据项？')
                .then(function () {
                    return delMaterialType(dictIds)
                })
                .then(() => {
                    this.getList()
                    this.$modal.msgSuccess(this.$t('processDefinition.successfullyDeleted'))
                })
                .catch(() => {})
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.dialogType = 3
            this.form = row
            this.visible = true
            // if(row.hasRead == 0){
            //   readNotice(row.noticeId).then(res=>{
            //     if(res.code == 200){
            //       this.handleQuery()
            //     }
            //   })
            // }
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            this.dialogType = 2
            this.form = row
            this.visible = true
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        // 导入
        handleImport() {
            this.$refs['excel-upload-input'].click()
        },
        async handleClick(e) {
            try {
                const formData = new FormData()
                formData.append('file', e.target.files[0])
                const res = await importMaterialTypeExcel(formData)
                if (res.code == 200) {
                    this.$message.success('导入成功')
                    this.getList()
                    this.$refs['excel-upload-input'].value = ''
                }
            } catch (error) {
                this.$refs['excel-upload-input'].value = ''
            }
        },
        /** 导出按钮操作 */
        handleExport() {
            // const queryParams = this.queryParams
            // this.$modal.confirm(this.$t('MaterialType.export')).then(() => {
            //   this.exportLoading = true
            //   return exportMaterialType(queryParams)
            // }).then(response => {
            //   this.$download.name(response.msg)
            //   this.exportLoading = false
            // }).catch(() => {})
            this.download(
                'masterdata/materialMin/export',
                {
                    ...this.queryParams,
                },
                `materialType_${new Date().getTime()}.xlsx`
            )
        },
        handleImport() {
            this.$refs['excel-upload-input'].click()
        },
        async handleClick(e) {
            try {
                const formData = new FormData()
                formData.append('file', e.target.files[0])
                const res = await importMaterialType(formData)
                if (res.code == 200) {
                    this.$message.success('导入成功')
                    this.getList()
                    this.$refs['excel-upload-input'].value = ''
                }
            } catch (error) {
                this.$refs['excel-upload-input'].value = ''
            }
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    padding: 3px 0 10px;
    display: inline-flex;
    justify-content: center;
    border-bottom: 2px solid #0b7be3;
}
.header-right {
    float: right;
}
.container-header {
    border-bottom: 1px solid #ededf2;
}
.container-table {
    float: left;
    //margin-top:6px;
    width: 100%;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}

.right-btns ::v-deep .el-button {
    margin-top: 0;
}
.app-container {
    padding: 0;
}
.table-action-wrap {
    padding: 12px 0;
}
.mt10 ::v-deep .el-form-item {
    margin-bottom: 0;
}
.mt10 ::v-deep .el-tabs__header {
    background-color: #fff;
}
.mt10 ::v-deep .is-active {
    border-top: 1px solid #1890ff;
}
.list-container ::v-deep .el-aside {
    display: none;
}
</style>
